/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.asiainfo.utils.sql.sqlbuilder.select;

import java.util.LinkedList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;

public class Select {
	private Context context;
	private final List<String> columns;

	public Select(Context context) {
		this.context = context;
		this.context.append("SELECT");
		this.columns = new LinkedList();
	}

	public From from() {
		this.context.append(StringUtils.join(this.columns, ",\n"));
		return new From(this.context);
	}

	public Select all() {
		append("*");
		return this;
	}

	public Select column(String column) {
		append(column);
		return this;
	}

	public Select count(String column) {
		append("COUNT(" + column + ")");
		return this;
	}

	private void append(String expression) {
		this.columns.add(expression);
	}
}